home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Documents / JAVA Programming / examples / 16 / PanelDemo.java < prev    next >
Encoding:
Java Source  |  2000-09-08  |  965 b   |  38 lines

  1. /* <applet code = "PanelDemo"
  2.            width=300
  3.            height=300>
  4.    </applet>
  5. */ 
  6.  
  7. import java.awt.*;
  8. import java.applet.*;
  9. class GrayCanvas extends Canvas { 
  10. Color gray;
  11. public GrayCanvas(float g) { 
  12. gray = new Color(g, g, g);
  13. }
  14. public void paint(Graphics g) { 
  15. Dimension size = size();
  16. g.setColor(gray);
  17. g.fillRect(0, 0, size.width, size.height);
  18. g.setColor(Color.black);
  19. g.drawRect(0, 0, size.width-1, size.height-1);
  20. } }
  21.  
  22. public class PanelDemo extends Applet { 
  23. static final int n = 4;
  24. public void init() { 
  25. setLayout(null);
  26. int width = Integer.parseInt(getParameter("width"));
  27. int height = Integer.parseInt(getParameter("height"));
  28. for (int i = 0; i < n; i++) { 
  29.      for (int j = 0; j < n; j++) {
  30.           float g = (i * n + j) / (float) (n * n);
  31.           Canvas c = new GrayCanvas(g);
  32.           add(c);
  33.           c.resize(width / n, height / n);
  34.           c.move(i * width / n, j * height / n);
  35.      } 
  36. }
  37. } }
  38.